package com.cb.eduservice.controller;


import com.cb.eduservice.client.VodClient;
import com.cb.eduservice.entity.EduVideo;
import com.cb.eduservice.service.EduVideoService;
import com.cb.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author Cebb
 * @since 2020-06-22
 */
@Api(description = "课程视频管理")

@RestController
@RequestMapping("/eduservice/video")
public class EduVideoController {

    private final EduVideoService videoService;

    @Autowired
    public EduVideoController(EduVideoService eduVideoService) {
        this.videoService = eduVideoService;
    }

    @ApiOperation("添加小节")
    @PostMapping
    public R addVideo(@RequestBody EduVideo eduVideo){
        videoService.save(eduVideo);

        return R.ok();
    }

    @ApiOperation("根据小节id删除关联信息")
    @DeleteMapping("{id}")
    public R removeVideo(@PathVariable String id){
        boolean flag = videoService.removeByVideoId(id);
        if (!flag) {
            return R.error().message("删除失败, 请稍后重试!");
        }

        return R.ok();
    }

    @ApiOperation("修改小节")
    @PutMapping("{id}")
    public R updateVideo(@PathVariable("id") String id,@RequestBody EduVideo eduVideo){
        eduVideo.setId(id);
        videoService.updateById(eduVideo);

        return R.ok();
    }

//    @ApiOperation("根据章节Id查询小节信息")
//    @GetMapping("{id}")
//    public R getVideoById(@PathVariable String id){
//        videoService.removeById(id);
//
//        return R.ok();
//    }
}

